import os.path
import random

import yaml
from faker import Faker

fileStream = open("../config/data.yaml", encoding="utf8")
data = yaml.safe_load(fileStream)

# print(data)
# print("--------------------------------")
print(data.get("hero"))
# print(data.get("hero_1"))
# print(data.get("hero_name"))
print(data.get("hero_name_word"))
# print(data.get("heros"))
# print(data.get("hero_name_list"))
# print(data.get("test"))


def read_data():
    fileStream = open("../config/data.yaml", encoding="utf8")
    # load读取的data类型是”字典“
    data = yaml.safe_load(fileStream)
    return data


current_path = os.path.realpath(__file__)
utils_path = os.path.dirname(current_path)
root_path = os.path.dirname(utils_path)

config_path = os.path.join(root_path, "config")
yaml_path = os.path.join(config_path, "data.yaml")
# yaml_path = os.path.join(config_path, "config", "data.yaml")

print(current_path)
print(utils_path)
print(root_path)

print(config_path)
print(yaml_path)





# Faker库：生成伪数据
faker = Faker(locale="zh-CN")

def random_name():
    name = faker.name()
    return name

# data = {'name': 'random_name()', 'age': 18, 'sex': '男'}
def func_yaml(data):
    if isinstance(data, dict):
        for key, value in data.items():
            if '${' and '}' in str(value):
                index_start = str(value).index('${')
                index_end = str(value).index('}')
                func_name = str(value)[index_start+2:index_end]
                data[key] = eval(func_name)
    return data

# print(random_name())

# data = {'name': 'random_name()', 'age': 18, 'sex': '男'}
# data_new = func_yaml(data)
# print(data_new)

data = {'name': '${random_name()}', 'age': 18, 'sex': '男'}
data_new = func_yaml(data)
print(data_new)


def age():
    return random.randint(10, 100)


